using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Caching;
using ViewStateEliminator.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;

namespace ViewStateEliminator.Data
{
    /// <summary>
    /// Uses Enterprise Librarys Caching block to store viewstate in the application cache.
    /// </summary>
    class ViewStateApplicationCacheStorage: ViewStateEliminator.Data.IViewstateStorage
    {
        private CacheManager _cache;
        #region IViewstateStorage Members
        public ViewStateApplicationCacheStorage()
        {
            _cache = CacheFactory.GetCacheManager("ViewStateApplicationCacheStorage");
        }
        public void Add(KeyValuePair<object, string> viewstateItem)
        {         
            _cache.Add(viewstateItem.Key.ToString(), viewstateItem.Value);
        }
        public KeyValuePair<object, string> Get(object key)
        {
            return new KeyValuePair<object, string>(key, ((string) _cache.GetData(key.ToString())));
        }
        public void Remove(object key)
        {
            _cache.Remove(key.ToString());
        }
        #endregion
    }
}
